package com.lqfan.autoAnswerQ.service.user.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lqfan.autoAnswerQ.controller.importQuestions.PoiWordController;
import com.lqfan.autoAnswerQ.dao.user.UserMapper;
import com.lqfan.autoAnswerQ.model.user.User;
import com.lqfan.autoAnswerQ.service.user.IUserService;
import com.lqfan.autoAnswerQ.utils.ResponseMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    private static final Logger logger = LoggerFactory.getLogger(PoiWordController.class);

    @Autowired
    private IUserService iUserService;
    private UserMapper userMapper;
    @Override
    public boolean  saveUser(String userName, String password, String phone) {
        User user = new User();
        user.setUserName(userName);
        user.setPassword(password);
        user.setPhone(phone);
        boolean checkName = findUser(userName);
        if (checkName){
           return false;
        }else {

            boolean saveRes = save(user);
            return saveRes;
        }

    }

    @Override
    public boolean findUser(String userName) {
        User user = new User();
        user.setUserName(userName);
//        super.getById(user)
//        return userMapper.findUser(userName);
        String value = baseMapper.findUser(userName);
        if (value==null||value.equals("")){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public boolean checkLogin(String userName, String password) {
        String login = baseMapper.checkUser(userName,password);
        if (login==null||login.equals("")){
            return false;
        }
        return true;
    }

    @Override
    public boolean updatePass(String userName, String phone, String password) {
        boolean updatePass = baseMapper.updatePass(userName,phone,password);
        return updatePass;
    }
}
